<template>
    <view class="draft">
        <Navigation backType="back" title="本地草稿" background="#fff" />
        <view class="f ai-c ph-32 h-72 warn">
            <image src="http://cwht.ricecs.cn/app/mine/warn.png" class="w-32 h-32 mr-12"></image>
            <view class="fs-28">草稿在应用卸载后会被删除，请及时发布</view>
        </view>
        <view class="ph-24 pv-20" v-for="(item,index) in list">
            <view class="b-24 list ph-28 pv-28">
                <view class="f ai-c jc-s-b">
                    <view class="f ai-c">
                        <image :src="item.avatar" class="w-80 h-80 b-80 mr-16"></image>
                        <view>
                            <view class="fs-30 fw-600 text-color4">{{item.memberNickname}}</view>
                            <!-- <view class="fs-24 text-color3 mt-4">6小时前</view> -->
                        </view>
                    </view>
                    <image src="http://cwht.ricecs.cn/app/index/del.png" class="w-32 h-32" @click='del(item)'></image>
                </view>
				<view class="mt-28 fs-28 text-color4 text-ellipsis-2">{{item.content}}</view>
				<!-- <view>{{item.content}}</view> -->
                <!-- <image class="mt-26 w-360 h-480 b-12" src="../static/logo.png" ></image> -->
            </view>
        </view>
    </view>
</template>
<script setup lang="ts">
	
	import { onLoad, onReachBottom, onPullDownRefresh } from '@dcloudio/uni-app';
	import { ref } from 'vue';
	import { getBaseUrl } from '@/utils/env';
	import { draftPage,draftDel } from '@/services/api/novice';
	import { dictDataType } from '@/services/api/dict';
	const curt = ref(0);
	const typeList = ref<any[]>([]);
	const list = ref<any[]>([]);
	const listParams = ref<any>({
	    pageNo: 1,
	    pageSize: 10,
	    category: '',
	});
	onLoad(() => {
	    list.value = [];
	    listParams.value.pageNo = 1;
	   getList()
	});
	//下拉刷新
	onPullDownRefresh(() => {
	    list.value = [];
	    listParams.value.pageNo = 1;
	    getList();
	});
	//上拉加载
	onReachBottom(() => {
	    listParams.value.pageNo++;
	    getList();
	});
	async function getList() {
	    const { data } = await draftPage(listParams.value);
	    uni.stopPullDownRefresh();
	    list.value = list.value.concat(data.list);
	}
	

	function toDetail(item: any) {
	    uni.navigateTo({
	        url: `/pages_mine/questionDetail?id=${item.id}`,
	    });
	}
	async function del(item: any) {
	    await draftDel({id:item.id});
	    uni.showToast({
	        title: '删除成功',
	        icon: 'none',
	    });
		list.value = [];
		listParams.value.pageNo = 1;
		getList();
	}

	//底部安全距离
	const systemInfo = uni.getSystemInfoSync();
	let safeArea = systemInfo.safeArea;
	let screenHeight = systemInfo.screenHeight;
	let safeAreaBottom = screenHeight - safeArea.bottom;
	
	
</script>
<style lang="scss" scoped>
.draft {
    background: #f5f5f5;
    min-height: 100vh;
    .list {
        background: #fff;
    }
    .warn {
        background: #fff5ed;
        color: #fa7f28;
    }
}
</style>
